<template>
  <div class="app-container">
    <el-row style="margin-bottom: 10px">
      <el-col :span="5">
        <div class="grid-content bg-purple" F>
          <span class="grid">订单编号</span>
          <el-input
            v-model="form.orderId"
            placeholder="请输入订单编号"
          ></el-input>
        </div>
      </el-col>
      <el-col :span="3">
        <div class="grid-content bg-purple">
          <el-radio v-model="form.status" label="1">已付款</el-radio>
          <el-radio v-model="form.sendStatus" label="1">已发货</el-radio>
        </div></el-col
      >
      <el-col :span="2">
        <el-button type="primary" @click="fetchData" plain>查询</el-button>
      </el-col>
      <el-col :span="1">
        <el-button @click="clear" type="success" plain>清空</el-button>
      </el-col>
    </el-row>

    <br />
    <el-table
      v-loading="listLoading"
      :data="list"
      show-header
      element-loading-text="Loading"
      border
      fit
      highlight-current-row
    >
      <el-table-column align="center" label="订单ID" width="200">
        <template slot-scope="scope">
          <!-- {{ scope.$index }} -->
          {{ scope.row.orderId }}
        </template>
      </el-table-column>
      <el-table-column label="订单价格">
        <template slot-scope="scope">
          {{ scope.row.paymentMoney }}
        </template>
      </el-table-column>
      <el-table-column label="是否付款">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.status == 1" type="success">已付款</el-tag>
          <el-tag v-if="scope.row.status == 0" type="info">未付款</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="是否发货">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.sendStatus == 1" type="success"
            >已发货</el-tag
          >
          <el-tag v-if="scope.row.sendStatus == 0" type="info">未发货</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="下单时间">
        <template slot-scope="scope">
          {{ scope.row.gmtCreate }}
        </template>
      </el-table-column>
      <el-table-column label="下单人">
        <template slot-scope="scope">
          {{ scope.row.nickname }}
        </template>
      </el-table-column>

      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button @click="update(scope.row.orderId)" type="primary" plain
            >发货</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <div class="block">
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="form.pageNum"
        :page-sizes="[6, 10, 30, 50]"
        :page-size="form.limit"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>

  </div>
</template>

<script>
import { listOrders } from "@/api/order";
import { updateOrderStatus } from "@/api/order";
export default {
  filters: {
    statusFilter(status) {
      const statusMap = {
        published: "success",
        draft: "gray",
        deleted: "danger",
      };
      return statusMap[status];
    },
  },
  data() {
    return {
      list: null,
      total: 0,
      listLoading: true,
      form: {
        orderId: "",
        pageNum: 1,
        limit: 10,
        status: 0,
        sendStatus: 0,
      },
    };
  },
  created() {
    this.fetchData();
  },
  methods: {
    update(orderId) {
      updateOrderStatus(orderId)
        .then((res) => {
          this.$message.success("发货成功");
          this.fetchData();
        })
        .catch((reason) => {
          // console.log(reason)
          // this.$message.error(reason);
        });
    },
    clear() {
      this.form = {
        orderId: "",
        pageNum: 1,
        limit: 10,
        status: 0,
        sendStatus: 0,
      };
      this.fetchData();
    },

    handleSizeChange(val) {
      this.form.limit = val;
      this.fetchData();
    },
    handleCurrentChange(val) {

      this.form.pageNum = val;
      this.fetchData();
    },
    fetchData() {
      this.listLoading = true;

      listOrders(this.form).then((response) => {
        console.log(response);
        this.list = response.data.orderList;

        this.total = response.data.total;
        this.listLoading = false;
      });
    },
    open2(productId) {
      this.$confirm("是否删除?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          deleteProductById(productId)
            .then((res) => {
              this.$message({
                type: "success",
                message: "删除成功!",
              });
              this.fetchData();
            })
            .catch((reason) => {
              this.$message({
                type: "error",
                message: resason,
              });
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    edit(productId) {
      this.$router.push({
        path: "/product/edit",
        query: {
          productId: productId,
        },
      });
    },
  },
};
</script>

<style  scoped>
.grid-content {
  display: flex;
  align-items: center;
  justify-content: center;
  /* jus */
}
.grid {
  font-weight: 600;
  color: #606266;
}
/deep/ .has-gutter th {
  background-color: #f8f8f9;
}
</style>>

